<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>span_not 查询 | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'query-dsl-span-not-query.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-span-not-query.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-span-not-query.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/query-dsl-span-not-query.html" rel="nofollow" target="_blank">../en/query-dsl-span-not-query.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch 权威指南 [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="query-dsl.html">查询领域特定语言(Query DSL)</a></span>
»
<span class="breadcrumb-link"><a href="span-queries.html">跨度(span)查询</a></span>
»
<span class="breadcrumb-node">span_not 查询</span>
</div>
<div class="navheader">
<span class="prev">
<a href="query-dsl-span-near-query.html">« span_near 查询</a>
</span>
<span class="next">
<a href="query-dsl-span-or-query.html">span_or 查询 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="query-dsl-span-not-query"></a>span_not 查询<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/query-dsl/span-not-query.asciidoc">edit</a>
</h2>
</div></div></div>

<p>
删除与另一个 span 查询重叠的匹配项，或者位于另一个 span 查询之前的 x 标记(由参数 <code class="literal">pre</code> 控制) 或 之后的 y 标记(由参数 <code class="literal">post</code> 控制) 内的匹配项。

span_not 查询对应 Lucene 的 <code class="literal">SpanNotQuery</code>。这里有一个例子：
</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_search
{
    "query": {
        "span_not": {
            "include": {
                "span_term": {"field1": "hoya"}
            },
            "exclude": {
                "span_near": {
                    "clauses": [
                        {"span_term": {"field1": "la"}},
                        {"span_term": {"field1": "hoya"}}
                    ],
                    "slop": 0,
                    "in_order": true
                }
            }
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/224.console"></div>
<p>
<code class="literal">include</code> 和 <code class="literal">exclude</code> 子句可以是任何 span 类型的查询。

<code class="literal">include</code> 子句是过滤匹配项的 span 查询，<code class="literal">exclude</code> 子句是匹配项不能与返回项重叠的 span 查询。
</p>
<p>
在上面的例子中，除了前面有<em>la</em>的文档之外，所有带有<em>hoya</em>的文档都被过滤了。
</p>
<p>其他顶级选项有：</p>
<div class="informaltable">
<table border="0" cellpadding="4px">
<colgroup>
<col>
<col>
</colgroup>
<tbody valign="top">
<tr>
<td valign="top">
<p>
<code class="literal">pre</code>
</p>
</td>
<td valign="top">
<p>
如果设置了，则包含 span 之前的词元数量不能与 exclude span 重叠。  
默认值为 0。
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<code class="literal">post</code>
</p>
</td>
<td valign="top">
<p>
如果设置了，则包含 span 后的词元数量不能与 exclude span 重叠。
默认值为 0。  
</p>
</td>
</tr>
<tr>
<td valign="top">
<p>
<code class="literal">dist</code>
</p>
</td>
<td valign="top">
<p>
如果设置了，包含 span 内的词元数量不能与 exclude span 重叠。

相当于设置了 <code class="literal">pre</code> 和 <code class="literal">post</code>。
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="query-dsl-span-near-query.html">« span_near 查询</a>
</span>
<span class="next">
<a href="query-dsl-span-or-query.html">span_or 查询 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>